open Icode
;;

let global_env = ref [] 
;;

let local_env = ref [] 
;;

let the_fenv = ref []
;;

let new_localscope localscope =
  local_env := localscope
;;

let make_poslist l =
  let rec do_makeposlist l poslist cnt = match l with
    | [] -> poslist
    | h::t -> (do_makeposlist t (poslist @ [(h,cnt)]) (cnt + 1))
  in
    do_makeposlist l [] 0
;;

let init_vars globals =
  global_env := make_poslist (List.map fst globals)
;;

let query_var id =
  try 
    Temp (List.assoc id !local_env)
  with
      Not_found -> Mem (List.assoc id !global_env)
;;

let init_funs (fenv : (string * Frame.frame_t) list) =
  the_fenv := fenv
;;

let query_fun id =
  List.assoc id !the_fenv
;;







